<template>
	<view class="page">

		<view class="message-board">
			<view class="ipt">
				<input class="uni-input" placeholder="留个言吧" focus v-model="leavemsg" />
			</view>
			<button class="btn" @click="sendLeaveMsg">发送</button>
		</view>

		<view class="content">
			<view class="one" v-for="(item,index) in msgList">
				<view class="information">
					<view>
						<image src="../img/user.png" alt="" class="image"></image>
					</view>
					<view class="text">
						<view class="user">用户{{ item.userid }}</view>
						<view class="date">{{ item.createtime.split('T')[0] }} {{ item.createtime.split('T')[1] }}</view>
					</view>
				</view>
				<view class="guestbook">{{ item.conent }}</view>
				<view class="reply">
					<view class="nickname" v-for="(one, i) in item.writemsgs" :key="i">管理员:<span
							class="text">{{ one.MsgContent }}</span>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getMessageList,
		sendMessage
	} from '@/utils/api.js'
	export default {
		data() {
			return {
				leavemsg: '',
				totalPage: null,
				msgList: [],
				isNull: false, // 是否还有数据
				isSend: false, // 是否是发送留言
			}
		},
		onLoad() {
			this.getMessageList()
		},
		methods: {
			sendLeaveMsg() {
				console.log(this.$store.state.vx_uid);
				this.isSend = true
				let time = new Date().getTime() + 8 * 60 * 60 * 1000
				time = new Date(time).toISOString()
				let time2 = time.replace('T',' ')
				time2 = time2.split('.')[0]
				let data = {
					// UserId: this.$store.state.vx_uid
					UserId: 1,
					SendTime: time2,
					MsgContent: this.leavemsg,
					MessageTypeId: 2,
					FileId: null
				}
				sendMessage(data).then((res) => {
					console.log(res);
					this.leavemsg = ''
					this.getMessageList()
				})
			},
			getMessageList() {
				let data = {
					beginTime: null,
					endTime: null,
					pageNo: 1,
					pageSize: 20
				}
				getMessageList(data).then((res) => {
					// console.log(res);
					this.totalPage = res.Data.length
					if (!this.isSend) {
						this.msgList = this.msgList.concat(res.Data)
					} else {
						this.msgList = res.Data
					}
				})
			},

		}
	}
</script>

<style lang="scss" scoped>
	.page {

		.message-board {
			background-color: #fff;
			box-shadow: 0px 0px 3px 2px rgb(243, 239, 239);
			width: 100%;
			display: flex;
			justify-content: space-around;
			align-items: center;
			padding: 20rpx;

			.ipt {
				width: 68%;
				padding: 10rpx 20rpx;
				border: darkgrey 1rpx solid;
				border-radius: 10rpx;
				// line-height: 40rpx;
			}

			.btn {
				// width: ;
				color: white;
				background-color: rgb(25, 137, 250);
				height: 60rpx;
				line-height: 60rpx;
			}
		}

		.content {

			.one {
				padding: 15rpx;
				margin-bottom: 16rpx;
				background-color: #fafafa;

				.information {
					display: flex;

					.image {
						width: 80rpx;
						height: 80rpx;
					}

					.text {
						margin-left: 20rpx;
						display: flex;
						flex-direction: column;
					}

					.user {
						margin-top: 8rpx;
						font-size: 12px;
					}

					.date {
						margin-top: 5rpx;
						font-size: 10px;
					}
				}

				.guestbook {
					text-indent: 2em;
				}

				.message-board {
					margin-top: 1rem;
					width: 100%;
					height: 2.5rem;
					line-height: 2.5rem;
					display: flex;
					justify-content: space-around;
					align-items: center;

					.ipt {
						// background-color: #f7f6f6;
						background-color: #fff;
						border: none;
						outline: none;
						width: 75%;
						height: 2rem;
						border-radius: 0.3125rem;
						padding-left: 1rem;
					}

					.btn {
						font-size: 0.9rem;
						height: 2rem;
						line-height: 2rem;
						text-align: center;
						border: none;
						outline: none;
						margin-left: 0.5rem;
						border-radius: 0.3125rem;
						padding: 0 0.5rem;
					}
				}

				.reply {
					// border-top: 1px gray solid;
					margin-top: 1rem;
					margin-left: 0.5rem;
					font-size: 0.85rem;
					color: rgb(92, 90, 90);

					.nickname {
						// color: rgb(39, 116, 218);
						color: black;
					}

					.text {
						color: rgb(92, 90, 90);
						margin-left: 0.5rem;
					}
				}
			}
		}
	}
</style>